package inventory.daoImplementer;

import dbhandelling.Crude;
import dto.MaterialMaster;
import inventory.daoInterface.MaterialMasterDao;


public class MaterialMasterImplementor extends Crude implements MaterialMasterDao
{
	
	@Override
	public void add(MaterialMaster materialMaster) throws Exception 
	{
		insert(materialMaster);
	}

	@Override
	public void update(MaterialMaster materialMaster) throws Exception 
	{
		super.update("MaterialMaster", "mCode", materialMaster.getmCode(),"mName",materialMaster.getmName());
		super.update("MaterialMaster", "mCode", materialMaster.getmCode(),"catCode",materialMaster.getCatCode());	
		super.update("MaterialMaster", "mCode", materialMaster.getmCode(),"status",materialMaster.getStatus()+"");
		super.update("MaterialMaster", "mCode", materialMaster.getmCode(),"mUnit",materialMaster.getmUnit());
	}

	@Override
	public void delete(MaterialMaster materialMaster) throws Exception 
	{
		super.delete("MaterialMaster", "mCode",materialMaster.getmCode());
	}

	@Override
	public MaterialMaster retreive(String conditionField, String ConditionValue) throws Exception 
	{
		MaterialMaster materialMaster=(MaterialMaster) super.retreive("MaterialMaster",conditionField, ConditionValue);
		return materialMaster;
	}

	@Override
	public MaterialMaster[] retreiveArray(String conditionField, String conditionValue) throws Exception 
	{
		MaterialMaster[] materialMasters;
		Object[] obj=super.retreiveArrayOnCondition("MaterialMaster", conditionField, conditionValue);
		materialMasters=new MaterialMaster[obj.length];
		
		for(int i=0;i<materialMasters.length;i++)
		{
			materialMasters[i]=(MaterialMaster) obj[i];
		}
		
		return materialMasters;
	}

	@Override
	public MaterialMaster[] retreiveAll() throws Exception 
	{
		MaterialMaster[] materialMasters;
		
		Object[] obj=super.retreiveAll("MaterialMaster");
		
		materialMasters=new MaterialMaster[obj.length];
		
		for(int i=0;i<materialMasters.length;i++)
		{
			materialMasters[i]=(MaterialMaster) obj[i];
		}
		
		return materialMasters;
	}

}
